package ar.edu.caece.pl.asem.model.impl.treeelements;

import ar.edu.caece.pl.asem.label.LabelGenerator;

public class Menor extends AbstractElement {

	public Menor() {
		this.label = "CONDICION <";
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Menor))
			return false;
		Menor other = (Menor) obj;
		if (label == null) {
			if (other.label != null)
				return false;
		} else if (!label.equals(other.label))
			return false;
		return true;
	}

	@Override
	public void generateASMCode() {
		StringBuffer sb = new StringBuffer();
		LabelGenerator.getInstance().getActualLabel();

		// Codigo expression izquierda
		this.getChildren().get(0).parent = this;
		this.getChildren().get(0).generateASMCode();
		sb.append(this.getChildren().get(0).code);
		sb.append("\t mov cx, ax \n");
		// Codigo expression derecha
		this.getChildren().get(1).parent = this;		
		this.getChildren().get(1).generateASMCode();
		sb.append(this.getChildren().get(1).code);
		sb.append("\t mov bx, ax \n");
		sb.append("\t mov ax, cx \n");
		sb.append("\t cmp ax, bx \n");
		String actualLabel = LabelGenerator.getInstance().getActualLabel();

		sb.append("jge \t " + actualLabel + " \n");

		this.code = sb.toString();

	}
}
